const mongoose = require('./db')
//用户表
const userSchema = mongoose.Schema({
    username: String,
    password: String,
    role: {
        type: mongoose.Types.ObjectId,
        ref: 'role',
        default: '66f010c38dcf9b1c16e1e216'
    }
})
const userModel = mongoose.model('user', userSchema)
//角色表
const roleSchema = mongoose.Schema({
    name: String,
    permissions: [{
        type: mongoose.Types.ObjectId,
        ref: 'permission'
    }]
})
const roleModel = mongoose.model('role', roleSchema)
//权限表
const permissionSchema = mongoose.Schema({
    name: String,
    url: String,
    level: Number,
    parentId: {
        type: mongoose.Types.ObjectId,
        ref: 'permission',
        default: null
    },
    iconClass: String
})

const permissionModel = mongoose.model('permission', permissionSchema)
module.exports = {
    userModel,
    roleModel,
    permissionModel
}
